﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
		
			div{
				width: 10%;
				height: 10%;
				border: 2px solid black;
				text-align: center;
				position: absolute;
			}
			
		</style>
	</head>
	<body>
		<div id='div'>
			<h1>小广告</h1>
		</div>
		<script>
			var w = window.innerWidth;
			var h = window.innerHeight;
				var div=document.getElementById('div');
				var dw=div.offsetWidth;
				var x=0;
				var y=0;
				var n=0;
			window.onload=function(){
				
			  setInterval(time1,100);
			 
				
			}
			function time1(){
				if(n==0){
						x=x+0.02*w;
						y=y+0.02*h;
						div.style.left=x+'px';
						div.style.top=y+'px';
						if((x+dw)>w){
							n=1;
						}
					}else if(n==1){
						x=x-0.02*w;
						y=y-0.02*h;
						div.style.left=x+'px';
						div.style.top=y+'px';
						if(x<=0){
							n=0;
						}
					}
			}
			
		
			
		</script>
	</body>
</html>
